package com.joysuch.wwyt.bp.service.impl;

import cn.zlg.common.util.CollectionUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.joysuch.wwyt.api.dataaccess.OrientationDataSyncService;
import com.joysuch.wwyt.bp.BpSystemVideoSearchBean;
import com.joysuch.wwyt.bp.bean.BpSystemVideoAddBean;
import com.joysuch.wwyt.bp.bean.facility.BpProductionFacilityListBean;
import com.joysuch.wwyt.bp.bean.facility.BpProductionSearchBean;
import com.joysuch.wwyt.bp.entity.BpProductionFacility;
import com.joysuch.wwyt.bp.entity.BpSystemVideo;
import com.joysuch.wwyt.bp.entity.dto.BpStorageTankAreaDto;
import com.joysuch.wwyt.bp.entity.dto.BpStorageTankDto;
import com.joysuch.wwyt.bp.mapper.BpStorageTankAreaMapper;
import com.joysuch.wwyt.bp.mapper.BpStorageTankMapper;
import com.joysuch.wwyt.bp.repository.BpProductionFacilityDao;
import com.joysuch.wwyt.bp.repository.BpSystemVideoDao;
import com.joysuch.wwyt.bp.service.BpProductionFacilityService;
import com.joysuch.wwyt.bp.service.BpStorageTankAreaService;
import com.joysuch.wwyt.bp.service.BpSystemVideoService;
import com.joysuch.wwyt.common.constant.Constant;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.common.util.MapUtils;
import com.joysuch.wwyt.core.common.util.PageDataUtils;
import com.joysuch.wwyt.mh.bean.MhMajorHazardChemProductRelListBean;
import com.joysuch.wwyt.mh.bean.MhMonitoringPointListBean;
import com.joysuch.wwyt.mh.entity.MhMajorHazard;
import com.joysuch.wwyt.mh.entity.MhMonitoringPoint;
import com.joysuch.wwyt.mh.repository.MhMonitoringPointDao;
import com.joysuch.wwyt.mh.service.MhMajorHazardService;
import com.joysuch.wwyt.mh.service.MhMonitoringPointService;
import com.joysuch.wwyt.risk.bean.*;
import com.joysuch.wwyt.risk.entity.RiskDistrict;
import com.joysuch.wwyt.risk.entity.RiskPoint;
import com.joysuch.wwyt.risk.enums.BatchDrawingEnum;
import com.joysuch.wwyt.risk.repository.RiskDistrictDao;
import com.joysuch.wwyt.risk.repository.RiskPointDao;
import com.joysuch.wwyt.bp.service.BatchDrawingService;
import com.joysuch.wwyt.risk.service.RiskDistrictService;
import com.joysuch.wwyt.risk.service.RiskPointService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.joysuch.wwyt.risk.enums.BatchDrawingEnum.*;

/**
 * @author zero
 * @since 2022/1/4 10:16
 */
@Service
public class BatchDrawingServiceImpl implements BatchDrawingService {
    @Autowired
    private RiskDistrictService districtService;
    @Autowired
    private RiskDistrictDao riskDistrictDao;
    @Autowired
    private MhMonitoringPointService mhMonitoringPointService;
    @Autowired
    private MhMonitoringPointDao mhMonitoringPointDao;
    @Autowired
    private BpStorageTankAreaMapper storageTankAreaMapper;
    @Autowired
    private BpSystemVideoDao bpSystemVideoDao;
    @Autowired
    private BpProductionFacilityDao productionFacilityDao;
    @Autowired
    private RiskPointDao riskPointDao;
    @Autowired
    private BpStorageTankMapper storageTankMapper;
    @Autowired
    private BpSystemVideoService systemVideoService;
    @Autowired
    private BpProductionFacilityService bpProductionFacilityService;
    @Autowired
    private RiskPointService riskPointService;
    @Autowired
    private BpStorageTankAreaService bpStorageTankAreaService;
    @Autowired
    private MhMajorHazardService mhMajorHazardService;
    @Autowired
    private OrientationDataSyncService orientationDataSyncService;
    
    @Override
    public ResultBean drawFenceAndPoint(BatchDrawingSearchBean bean) {
        PageRequest page = PageRequest.of(bean.getPage(),bean.getSize());
        BatchDrawingEnum batchDrawingEnum = find(bean.getType());
        if (null == batchDrawingEnum){
            return ResultBean.defaultSuccessResult();
        }
        switch (batchDrawingEnum){
            case RISK_AREA:
                Pageable pageable = PageDataUtils.addOrderByDesc(page, "createTime");
                RiskDistrictListSearchBean searchBean = new RiskDistrictListSearchBean();
                searchBean.setName(bean.getName());
                searchBean.setStatus(bean.getStatus());
                Page<RiskDistrict> riskDistrictPage = districtService.findByPage(pageable, searchBean);
                List<BatchDrawingBean> convert = convert(riskDistrictPage.getContent(), RISK_AREA);
                return ResultBean.pageData(convert,riskDistrictPage.getTotalElements());
                
            case MONITORING_POINTS:
                Page<MhMonitoringPointListBean> mhMonitoringPointPage = mhMonitoringPointService.list(page, bean.getName(),null,null,1L,null,null, bean.getStatus());
                List<BatchDrawingBean> convert1 = convert(mhMonitoringPointPage.getContent(), MONITORING_POINTS);
                return ResultBean.pageData(convert1,mhMonitoringPointPage.getTotalElements());
                
            case TANK_FARM:
                Pageable pageable4 = PageDataUtils.addOrderByDesc(page, "id");
                IPage<BpStorageTankAreaDto> bpStorageTankAreaDtoIPage = bpStorageTankAreaService.findTankAreaByPage(pageable4, bean.getName(), bean.getStatus());
                if (null == bpStorageTankAreaDtoIPage){
                    return ResultBean.pageData(new ArrayList(),0L);
                }
                List<BatchDrawingBean> convert2 = convert(bpStorageTankAreaDtoIPage.getRecords(), TANK_FARM);
                return ResultBean.pageData(convert2,bpStorageTankAreaDtoIPage.getTotal());

            case VIDEO:
                Pageable pageable1 = PageDataUtils.addOrderByDesc(page, "id");
                BpSystemVideoSearchBean searchBean1 = new BpSystemVideoSearchBean();
                searchBean1.setName(bean.getName());
                searchBean1.setStatus(bean.getStatus());
                Page<BpSystemVideoAddBean> bpSystemVideoAddBeans = systemVideoService.list(pageable1, searchBean1);
                List<BatchDrawingBean> convert3 = convert(bpSystemVideoAddBeans.getContent(), VIDEO);
                return ResultBean.pageData(convert3,bpSystemVideoAddBeans.getTotalElements());

            case EQUIPMENT:
                Pageable pageable2 = PageDataUtils.addOrderByDesc(page, "id");
                BpProductionSearchBean searchBean2 = new BpProductionSearchBean();
                searchBean2.setName(bean.getName());
                searchBean2.setStatus(bean.getStatus());
                Page<BpProductionFacilityListBean> productionFacilityListBeans = bpProductionFacilityService.findByPage(pageable2, searchBean2);
                List<BatchDrawingBean> convert4 = convert(productionFacilityListBeans.getContent(), EQUIPMENT);
                return ResultBean.pageData(convert4,productionFacilityListBeans.getTotalElements());
                
            case RISK_POINT:
                Pageable pageable3 = PageDataUtils.addOrderByDesc(page, "id");
                RiskPointListBean.Search search = new RiskPointListBean.Search();
                search.setName(bean.getName());
                search.setStatus(bean.getStatus());
                search.setFlag(2);
                search.setBizId(1L);
                Page<RiskPointListBean> riskPointListBeans = riskPointService.findByPage(pageable3, search);
                List<BatchDrawingBean> convert5 = convert(riskPointListBeans.getContent(), RISK_POINT);
                return ResultBean.pageData(convert5,riskPointListBeans.getTotalElements());

            case STORAGE_TANK:
                
                Pageable pageable5 = PageDataUtils.addOrderByDesc(page, "id");
                IPage<BpStorageTankDto> storageTankDtoIPage = bpStorageTankAreaService.findTankByPage(pageable5, bean.getName(), bean.getStatus());
                if (null == storageTankDtoIPage){
                    return ResultBean.pageData(new ArrayList(),0L);
                }
                List<BatchDrawingBean> convert6 = convert(storageTankDtoIPage.getRecords(), STORAGE_TANK);
                return ResultBean.pageData(convert6,storageTankDtoIPage.getTotal());
                
            case RISK_SOURCE:

                Page<MhMajorHazard> majorHazardListBeanPage = mhMajorHazardService.page(page, bean.getName(), bean.getStatus());
                List<BatchDrawingBean> convert7 = convert(majorHazardListBeanPage.getContent(), RISK_SOURCE);
                return ResultBean.pageData(convert7,majorHazardListBeanPage.getTotalElements());
        }
        return null;
    }

    /**
     * 转化数据
     * @param list 原始数据
     * @param type 类型
     * @return
     */
    public List<BatchDrawingBean> convert(List list,BatchDrawingEnum type){
        List<BatchDrawingBean> batchDrawingBeanList = new ArrayList<>();
        if (CollectionUtils.isEmpty(list)){
            return batchDrawingBeanList;
        }
        switch (type){
            case RISK_AREA:
                List<RiskDistrict> riskDistrictList = list;
                for (RiskDistrict riskDistrict : riskDistrictList) {
                    BatchDrawingBean batchDrawingBean = new BatchDrawingBean();
                    batchDrawingBean.setName(riskDistrict.getName());
                    batchDrawingBean.setId(riskDistrict.getId());
                    whetherHaveLocation(riskDistrict.getCoordinates(), batchDrawingBean, 1);
                    batchDrawingBeanList.add(batchDrawingBean);
                }
                break;
            case MONITORING_POINTS:
                List<MhMonitoringPointListBean> mhMonitoringPointList = list;
                for (MhMonitoringPointListBean point : mhMonitoringPointList) {
                    BatchDrawingBean batchDrawingBean = new BatchDrawingBean();
                    batchDrawingBean.setName(point.getPointCode()+ Constant.EN_LEFT_BRACKETS + point.getName() + Constant.EN_RIGHT_BRACKETS );
                    batchDrawingBean.setId(point.getId());
                    whetherHaveLocation(point.getLocation(), batchDrawingBean, 0);
                    batchDrawingBeanList.add(batchDrawingBean);
                }
                break;
            case TANK_FARM:
                List<BpStorageTankAreaDto> bpStorageTankAreaDtoList = list;
                for (BpStorageTankAreaDto bpStorageTankAreaDto : bpStorageTankAreaDtoList) {
                    BatchDrawingBean batchDrawingBean = new BatchDrawingBean();
                    batchDrawingBean.setId(bpStorageTankAreaDto.getId());
                    batchDrawingBean.setName(bpStorageTankAreaDto.getCode() + Constant.EN_LEFT_BRACKETS + bpStorageTankAreaDto.getName() + Constant.EN_RIGHT_BRACKETS);
                    whetherHaveLocation(bpStorageTankAreaDto.getLocation(), batchDrawingBean, 1);
                    batchDrawingBeanList.add(batchDrawingBean);
                }
                break;
            case VIDEO:
                List<BpSystemVideoAddBean> bpSystemVideoAddBeans = list;
                for (BpSystemVideoAddBean bpSystemVideoAddBean : bpSystemVideoAddBeans) {
                    BatchDrawingBean batchDrawingBean = new BatchDrawingBean();
                    batchDrawingBean.setId(bpSystemVideoAddBean.getId());
                    batchDrawingBean.setName(bpSystemVideoAddBean.getName());
                    whetherHaveLocation(bpSystemVideoAddBean.getRegion(), batchDrawingBean, 1);
                    batchDrawingBeanList.add(batchDrawingBean);
                }
                break;
            case EQUIPMENT:
                List<BpProductionFacilityListBean> bpProductionFacilityListBeanList = list;
                for (BpProductionFacilityListBean bpProductionFacilityListBean : bpProductionFacilityListBeanList) {
                    BatchDrawingBean batchDrawingBean = new BatchDrawingBean();
                    batchDrawingBean.setId(bpProductionFacilityListBean.getId());
                    batchDrawingBean.setName(bpProductionFacilityListBean.getCode()+ Constant.EN_LEFT_BRACKETS + bpProductionFacilityListBean.getName() + Constant.EN_RIGHT_BRACKETS);
                    whetherHaveLocation(bpProductionFacilityListBean.getLocation(), batchDrawingBean, 0);
                    batchDrawingBeanList.add(batchDrawingBean);
                }
                break;
            case RISK_POINT:
                List<RiskPointListBean> riskPointListBeanList = list;
                for (RiskPointListBean riskPointListBean : riskPointListBeanList) {
                    BatchDrawingBean batchDrawingBean = new BatchDrawingBean();
                    batchDrawingBean.setId(riskPointListBean.getId());
                    batchDrawingBean.setName(riskPointListBean.getName()+ Constant.EN_LEFT_BRACKETS + riskPointListBean.getRiskDistrctName() + Constant.EN_RIGHT_BRACKETS);
                    whetherHaveLocation(riskPointListBean.getFenceData(),batchDrawingBean,1);
                    batchDrawingBeanList.add(batchDrawingBean);
                }
                break;
                
            case STORAGE_TANK:
                List<BpStorageTankDto> bpStorageTankDtoList = list;
                for (BpStorageTankDto bpStorageTankDto : bpStorageTankDtoList) {
                    BatchDrawingBean batchDrawingBean = new BatchDrawingBean();
                    batchDrawingBean.setId(bpStorageTankDto.getId());
                    batchDrawingBean.setName(bpStorageTankDto.getCode() + Constant.EN_LEFT_BRACKETS + bpStorageTankDto.getName() + Constant.EN_RIGHT_BRACKETS);
                    whetherHaveLocation(bpStorageTankDto.getLocation(), batchDrawingBean, 0);
                    batchDrawingBeanList.add(batchDrawingBean);
                }
                break;
                
            case RISK_SOURCE:
                List<MhMajorHazard> mhMajorHazardList = list;
                for (MhMajorHazard mhMajorHazard : mhMajorHazardList) {
                    BatchDrawingBean batchDrawingBean = new BatchDrawingBean();
                    batchDrawingBean.setId(mhMajorHazard.getId());
                    batchDrawingBean.setName(mhMajorHazard.getName());
                    whetherHaveLocation(mhMajorHazard.getLocation(),batchDrawingBean,0);
                    batchDrawingBeanList.add(batchDrawingBean);
                }
                break;
        }
        return batchDrawingBeanList;
    }

    @Override
    public void updateLocation(UpdateLocationBean bean) {
        switch (BatchDrawingEnum.find(bean.getType())){
            
            case RISK_AREA:
                RiskDistrict riskDistrict = districtService.findById(bean.getId());
                riskDistrict.setCoordinates(bean.getLocation());
                riskDistrictDao.save(riskDistrict);
                //同步
                List<RiskDistrict> orList = new ArrayList<>();
                orList.add(riskDistrict);
                orientationDataSyncService.riskDistrict(orList, "alterArea");
                break;
            case MONITORING_POINTS:
                MhMonitoringPoint monitoringPoint = mhMonitoringPointDao.getOne(bean.getId());
                monitoringPoint.setLocation(bean.getLocation());
                mhMonitoringPointDao.save(monitoringPoint);
                break;
            case TANK_FARM:
                BpStorageTankAreaDto bpStorageTankAreaDto = storageTankAreaMapper.selectById(bean.getId());
                bpStorageTankAreaDto.setLocation(bean.getLocation());
                storageTankAreaMapper.updateById(bpStorageTankAreaDto);
                break;
            case VIDEO:
                BpSystemVideo bpSystemVideo = bpSystemVideoDao.getOne(bean.getId());
                bpSystemVideo.setRegion(bean.getLocation());
                bpSystemVideoDao.save(bpSystemVideo);
                break;
            case EQUIPMENT:
                BpProductionFacility productionFacility = productionFacilityDao.getOne(bean.getId());
                productionFacility.setLocation(bean.getLocation());
                productionFacilityDao.save(productionFacility);
                break;
            case RISK_POINT:
                RiskPoint riskPoint = riskPointService.findById(bean.getId());
                RiskPoint riskPoint1 = resolveLocation(riskPoint, bean.getLocation());
                riskPointDao.save(riskPoint1);
                break;
            case STORAGE_TANK:
                BpStorageTankDto bpStorageTankDto = storageTankMapper.selectById(bean.getId());
                bpStorageTankDto.setLocation(bean.getLocation());
                storageTankMapper.updateById(bpStorageTankDto);
                break;
                
            case RISK_SOURCE:
                MhMajorHazardChemProductRelListBean majorHazardChemProductRelListBean = mhMajorHazardService.getById(bean.getId());
                majorHazardChemProductRelListBean.setLocation(bean.getLocation());
                mhMajorHazardService.edit(majorHazardChemProductRelListBean);
                break;
        }
    }


    //解析位置
    private RiskPoint resolveLocation(RiskPoint riskPoint,String fenceDataString) {
        if (StringUtils.isNotBlank(fenceDataString)) {
            riskPoint.setLocation(fenceDataString);
            FenceData fenceData = JSONObject.parseObject(fenceDataString, FenceData.class);
            //riskPoint.setPoints(fenceData.getPoints());
            List<FencePoint> points = fenceData.getPoints();
            String pointsStr = JSONArray.toJSON(points).toString();
            riskPoint.setPoints(pointsStr);
            riskPoint.setFloorId(fenceData.getFloorId());
            riskPoint.setBuildingId(fenceData.getBuildingId());
            //计算中心点位
            JSONArray pointArrayJson = JSONArray.parseArray(pointsStr);
            List<MapUtils.SafetyPoint> safetyPoints = pointArrayJson.toJavaList(MapUtils.SafetyPoint.class);
            MapUtils.SafetyPoint safetyPoint = MapUtils.calculateCenterPointZ(safetyPoints);
            riskPoint.setCenterPoint(JSON.toJSONString(safetyPoint));
        } else {
            riskPoint.setPoints(null);
            riskPoint.setFloorId(null);
            riskPoint.setBuildingId(null);
            riskPoint.setCenterPoint(null);
        }
        return riskPoint;
    }

    /**
     * 从区域位置信息中找到floorId
     * @param location
     * @return
     */
    private Long getFloorIdForArea(String location){
        
        JSONObject jsonObject = JSONObject.parseObject(location);
        MapUtils.SafetyPoints safetyPoints = JSON.toJavaObject(jsonObject, MapUtils.SafetyPoints.class);
        return safetyPoints.getFloorId();
    }

    /**
     *  从点位位置信息中找到floorId
     * @param location
     * @return
     */
    private Long getFloorIdForPoint(String location){
        JSONObject jsonObject = JSONObject.parseObject(location);
        MapUtils.SafetyPoint safetyPoint = JSON.toJavaObject(jsonObject, MapUtils.SafetyPoint.class);
        return safetyPoint.getFloorId();
    }

    /**
     * 判断数据是否拥有位置 
     * @param location
     * @param bean
     * @param type 位置类型 0: 点位 1: 区域
     * @return
     */
    private void whetherHaveLocation(String location , BatchDrawingBean bean , Integer type){
        if (StringUtils.isBlank(location)){
            bean.setStatus("未设置");
        }else {
            if (isJson(location)){
                bean.setLocation(location);
                bean.setStatus("已设置");
                //floorNo由前端自己判断
               /* if (0 == type ){
                    Long floorIdForPoint = getFloorIdForPoint(location);
                    bean.setFloorNo(floorIdForPoint);
                }else if (1 == type ){
                    Long floorIdForArea = getFloorIdForArea(location);
                    bean.setFloorNo(floorIdForArea);
                }*/
            }else {
                bean.setStatus("未设置");
            }
            
        }
    }

    /**
     * 判断一个字符串是否是json
     * @param str
     * @return
     */
    public static boolean isJson(String str){
        boolean result = false;
        try {
            Object parse = JSON.parse(str);
            result = true;
        }catch (Exception e){
        }
        return result;
    }

    @Override
    public List<Map<String, Long>> getQuantity(Integer type) {
        Long allNum = 0L;
        Long haveLocationNum = 0L;
        BatchDrawingEnum batchDrawingEnum = find(type);
        if (null == batchDrawingEnum){
            return null;
        }
        switch (batchDrawingEnum){
            case RISK_AREA:
                //allNum = districtService.getNumForHaveLocation(0);
                haveLocationNum = districtService.getNumForHaveLocation(1);
                break;
            case MONITORING_POINTS:
                //allNum = mhMonitoringPointService.getNumForHaveLocation(0);
                haveLocationNum = mhMonitoringPointService.getNumForHaveLocation(1);
                break;
            case TANK_FARM:
                //allNum = bpStorageTankAreaService.getNumForHaveLocationForArea(0);
                haveLocationNum = bpStorageTankAreaService.getNumForHaveLocationForArea(1);
                break;
            case VIDEO:
                //allNum = systemVideoService.getNumForHaveLocation(0);
                haveLocationNum = systemVideoService.getNumForHaveLocation(1);
                break;
            case EQUIPMENT:
                //allNum = bpProductionFacilityService.getNumForHaveLocation(0);
                haveLocationNum = bpProductionFacilityService.getNumForHaveLocation(1);
                break;
            case RISK_POINT:
                //allNum = riskPointService.getNumForHaveLocation(0);
                haveLocationNum = riskPointService.getNumForHaveLocation(1);
                break;
            case STORAGE_TANK:
                //allNum = bpStorageTankAreaService.getNumForHaveLocationForTank(0);
                haveLocationNum = bpStorageTankAreaService.getNumForHaveLocationForTank(1);
                break;
                
            case RISK_SOURCE:
                //allNum = mhMajorHazardService.getNumForHaveLocation(0);
                haveLocationNum = mhMajorHazardService.getNumForHaveLocation(1);
                break;
        }
        return convertResult(allNum,haveLocationNum);
    }

    /**
     * 转换为批量画围栏的角标
     * @return
     */
    private List<Map<String,Long>> convertResult(Long allNum,Long haveLocationNum){
        List<Map<String,Long>> result = new ArrayList<>();
        //Map<String,Long> allNumMap = new HashMap<>();
        Map<String,Long> haveLocationNumMap = new HashMap<>();
        //allNumMap.put("allCount",allNum);
        haveLocationNumMap.put("haveLocationCount",haveLocationNum);
        //result.add(allNumMap);
        result.add(haveLocationNumMap);
        return result;
    }

    @Override
    public ResultBean getAllFenceOrPoint(Integer type) {
        List<BatchDrawingBean> convert = new ArrayList<>();
        BatchDrawingEnum batchDrawingEnum = find(type);
        if (null == batchDrawingEnum){
            return null;
        }
        switch (batchDrawingEnum){
            case RISK_AREA:
                List<RiskDistrict> riskAreaList = districtService.findAllHaveLocation();
                convert = convert(riskAreaList, RISK_AREA);
                break;
            case MONITORING_POINTS:
                List<MhMonitoringPoint> pointList = mhMonitoringPointService.findAllHaveLocation();
                convert = covertForMonitoringPoint(pointList);
                break;
            case TANK_FARM:
                List<BpStorageTankAreaDto> tankAreaList = bpStorageTankAreaService.findAllHaveLocation();
                convert = convert(tankAreaList,TANK_FARM);
                break;
            case VIDEO:
                List<BpSystemVideo> videoList = systemVideoService.findAllHaveLocation();
                convert = covertForVideo(videoList);
                break;
            case EQUIPMENT:
                List<BpProductionFacility> facilityList = bpProductionFacilityService.findAllHaveLocation();
                convert = covertForEquipment(facilityList);
                break;
            case RISK_POINT:
                List<RiskPoint> riskPointList = riskPointService.findAllHaveLocation();
                convert = convertForRiskPoint(riskPointList);
                break;
            case STORAGE_TANK:
                List<BpStorageTankDto> tankList = bpStorageTankAreaService.findAllHaveLocationForTank();
                convert = convert(tankList,STORAGE_TANK);
                break;
            case RISK_SOURCE:
                List<MhMajorHazard> majorHazardList = mhMajorHazardService.findAllHaveLocationForTank();
                convert = convert(majorHazardList,RISK_SOURCE);
                break;
        }
        return ResultBean.success(convert);
    }

    /**
     * 风险点的转换
     * @param riskPointList
     * @return
     */
    private List<BatchDrawingBean> convertForRiskPoint(List<RiskPoint> riskPointList){
        List<BatchDrawingBean> result = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(riskPointList)){
            for (RiskPoint riskPoint : riskPointList) {
                BatchDrawingBean bean = new BatchDrawingBean();
                bean.setId(riskPoint.getId());
                bean.setName(riskPoint.getName()+ Constant.EN_LEFT_BRACKETS + riskPoint.getRiskDistrict().getName() + Constant.EN_RIGHT_BRACKETS);
                if (StringUtils.isNotBlank(riskPoint.getLocation())){
                    bean.setLocation(riskPoint.getLocation());
                }else {
                    setFenceToBatchDrawingBean(riskPoint,bean);
                }
                result.add(bean);
            }
        }
        return result;
    }
    
    private List<BatchDrawingBean> covertForMonitoringPoint(List<MhMonitoringPoint> pointList){
        List<BatchDrawingBean> result = new ArrayList<>();
        for (MhMonitoringPoint point : pointList) {
            BatchDrawingBean bean = new BatchDrawingBean();
            bean.setName(point.getPointCode()+ Constant.EN_LEFT_BRACKETS + point.getName() + Constant.EN_RIGHT_BRACKETS );
            bean.setId(point.getId());
            bean.setLocation(point.getLocation());
            result.add(bean);
        }
        return result;
    }

    private List<BatchDrawingBean> covertForVideo(List<BpSystemVideo> videoList){
        List<BatchDrawingBean> result = new ArrayList<>();
        for (BpSystemVideo bpSystemVideo : videoList) {
            BatchDrawingBean bean = new BatchDrawingBean();
            bean.setId(bpSystemVideo.getId());
            bean.setName(bpSystemVideo.getName());
            bean.setLocation(bpSystemVideo.getRegion());
            result.add(bean);
        }
        return result;
    }
    
    private List<BatchDrawingBean> covertForEquipment(List<BpProductionFacility> facilityList){
        List<BatchDrawingBean> result = new ArrayList<>();
        for (BpProductionFacility productionFacility : facilityList) {
            BatchDrawingBean bean = new BatchDrawingBean();
            bean.setId(productionFacility.getId());
            bean.setName(productionFacility.getCode()+ Constant.EN_LEFT_BRACKETS + productionFacility.getName() + Constant.EN_RIGHT_BRACKETS);
            bean.setLocation(productionFacility.getLocation());
            result.add(bean);
        }
        return result;
    }

    /**
     * 将风险点的三个围栏信息拼接成json赋值给bean
     *
     * @param riskPoint
     * @param bean
     */
    public void setFenceToBatchDrawingBean(RiskPoint riskPoint, BatchDrawingBean bean) {
        FenceData fenceData = new FenceData();
        String pointsStr = riskPoint.getPoints();
        if (StringUtils.isNotBlank(pointsStr)) {
            JSONArray pointArrayJson = JSONArray.parseArray(pointsStr);
            List<FencePoint> points = pointArrayJson.toJavaList(FencePoint.class);
            fenceData.setPoints(points);
            fenceData.setBuildingId(riskPoint.getBuildingId());
            fenceData.setFloorId(riskPoint.getFloorId());
            String fenceDataJson = JSONArray.toJSON(fenceData).toString();
            bean.setLocation(fenceDataJson);
        }
    }

    
}
